package com.apes.framework.rop.session.store;

import com.apes.framework.rop.session.SimpleSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SessionService {

    @Autowired
    private ApesSessionRepository repository;

    public void save(SimpleSession simpleSession) {
        ApesSession session = new ApesSession();
        session.setId(simpleSession.getSessionId());
        session.setIp(simpleSession.getIp());
        session.setUserId(simpleSession.getUserId());
        repository.save(session);
    }

    public void update(String sessionId) {
        ApesSession session = repository.findOne(sessionId);
        if (session == null) return;
        session.setLogoutOn(new Date());
        repository.save(session);
    }
}
